<template>
	<view class="content">
		<view class="inputBox" style="padding-bottom: 140rpx;">
			<view class="textView">
				<text>自我描述</text>
				<text>丰富的自我描述，更能赢得企业的青睐</text>
			</view>
			<u-input type="textarea" v-model="code" placeholder="简单描述下你的工作职责" :maxlength="1000"
				:height="500" :custom-style="customStyle" :placeholder-style="placeholderStyle" @input="getnum"
				:auto-height="true" ></u-input>
			<!-- 	<textarea @keyboardheightchange="getInput" :adjust-position="false"
				:style="'height:calc( '+height +' - 140rpx);'" :cursor-spacing="35" :auto-blur="true"
				:placeholder-style="placeholderStyle" style="width: 100%;font-size: 28rpx;" v-model="code"
				:auto-height="false" :maxlength="1000" placeholder="简单描述下你的工作职责" @input="getnum" /> -->
			<view class="currentWordNumber"><text>{{currentWordNumber}}</text>/1000</view>
		</view>
		<view class="bottomBoxBtn">
			<u-button hoverClass="none" :customStyle="customstyle" @click="$u.throttle(toSave, 2000)">保存</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				customstyle:{
					color:'#fff',
					background:'#00d075',
					bordern:'none'
				},
				code: '',
				type: '',
				currentWordNumber: 0,
				inputHeight: 0,
				customStyle: {
					width: '100%',
					fontSize: '28rpx'
				},
				placeholderStyle: "color: '#c0c4cc'",
				height: 0
			}
		},
		computed: {
			maxlength() {
				let cur = ''
				switch (this.type) {
					case "1":
						cur = 1000
						break;

				}
				return cur
			},
			title() {
				let res = ''
				switch (this.type) {
					case "1":
						res = '自我描述'
						break;
				}
				return res
			}
		},
		methods: {
			getnum(value) {
				var len = parseInt(value.length)
				console.log(len)
				if (len > 1000) {
					this.code = value.slice(0, 1000)
					this.currentWordNumber = 1000
				} else {
					this.currentWordNumber = len
				}
			},
			async toSave(code) {
				if (this.code.length > 1000) {
					this.code = this.code.slice(0, 1000)
				}
				let params = {
					specialty: this.code
				}
				let res = await uni.$u.api.specialty(
					params
				)
				if (res) {
					uni.$u.toast('保存成功')
					setTimeout(() => {
						uni.$u.route({
							type: 'back'
						})
					}, 1000)
				}
			},
		},
		onLoad(data) {
			this.type = data.type
			if (data.item) {
				let code = decodeURIComponent(data.item)
				this.code = JSON.parse(code)
				var len = parseInt(this.code.length)
				this.currentWordNumber = len
			}
		}

	}
</script>

<style lang="scss">
	.content {
		width: 100%;
		// height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 30rpx;
		background-color: #fff;


		.inputBox {
			width: 100%;
			display: flex;
			flex-direction: column;

			// padding-bottom: 140rpx;
			.textView {
				color: #867F7F;
				font-size: 26rpx;
				display: flex;
				flex-direction: column;
				margin-bottom: 20rpx;
				z-index: 0;

				text:nth-child(1) {
					color: #000;
					font-size: 36rpx;
					font-weight: bold;
					margin: 20rpx 0;
				}
			}
		}

		.btnBox {
			width: 684rpx;
			height: 68rpx;
			position: fixed;
			bottom: 100rpx;

			button {
				width: 684rpx;
				background-color: #0E6FF7;
				color: #fff;
				height: 68rpx;
				line-height: 68rpx;
				font-size: 28rpx;
				text-align: center;
				font-family: Arial;

				&::after {
					border: none;
				}

			}

		}

	}

	:deep .u-field {
		padding: 0 !important;
		margin: 20rpx 0;
	}

	:deep .u-flex-1 {
		margin: 0 !important;
	}
	

	.currentWordNumber {
		text-align: right;
		text{
			color: #00d075;
		}
	}

	.account {
		position: sticky;
		top: 0;
		z-index: 999;
	}

	.bottomBoxBtn {
		height: 140rpx;
		width: calc(100% - 60rpx);
		background-color: #fff;
		position: fixed;
		bottom: 0;
		z-index: 999;
		padding: 30rpx 0;

	}
</style>